package com.garlicts.framework.extension;

import java.util.List;

import com.garlicts.framework.ioc.BeanContainerComponent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.garlicts.framework.core.InstanceFactory;
import com.garlicts.framework.core.BeanLoader;
import com.garlicts.framework.core.fault.InitializationError;

/**
 * 初始化插件能力
 *
 * @author 水木星辰
 * @since 1.0
 */
public class PluginComponent {

	private static final Logger logger = LoggerFactory.getLogger(PluginComponent.class);
	
    /**
     * 创建一个插件列表（用于存放插件实例）
     */
//    private static final List<Plugin> pluginList = new LinkedList<Plugin>();

    private static final BeanLoader beanLoader = InstanceFactory.getBeanLoader();

    static {
        try {
        	
            // 获取并遍历所有的插件类（实现了 Plugin 接口的类）
            List<Class<?>> pluginClassList = beanLoader.getBeanClassListBySuper(Plugin.class);
            
            for (Class<?> pluginClass : pluginClassList) {

                Plugin plugin = (Plugin) BeanContainerComponent.getBean(pluginClass);
                plugin.init();

            }

        } catch (Exception e) {
            throw new InitializationError("初始化 PluginAbility 出错！", e);
        }
    }

//    /**
//     * 获取所有插件
//     */
//    public static List<Plugin> getPluginList() {
//        return pluginList;
//    }

}
